import Vue from 'vue'
import Router from 'vue-router'

// 实现路由懒加载，使用动态 import语法来定义代码分块点，
// 把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件
const Home = (resolve) => {
  import('@/views/home').then((module) => {
    resolve(module)
  })
}

const Login = (resolve) => {
  import('@/views/login').then((module) => {
    resolve(module)
  })
}

const Register = (resolve) => {
  import('@/views/register').then((module) => {
    resolve(module)
  })
}

const Search = (resolve) => {
  import('@/views/search').then((module) => {
    resolve(module)
  })
}

const Personal = (resolve) => {
  import('@/views/personal/personal').then((module) => {
    resolve(module)
  })
}

const familyMembers = (resolve) => {
  import('@/views/personal/children/familyMembers').then((module) => {
    resolve(module)
  })
}

const mydoctor = (resolve) => {
  import('@/views/personal/children/mydoctor').then((module) => {
    resolve(module)
  })
}


const Setting = (resolve) => {
  import('@/components/setting/setting').then((module) => {
    resolve(module)
  })
}

const shop = (resolve) => {
  import('@/views/shop/shop').then((module) => {
    resolve(module)
  })
}

const pay = (resolve) => {
  import('@/views/pay').then((module) => {
    resolve(module)
  })
}

const payment = (resolve) => {
  import('@/components/payment/payment').then((module) => {
    resolve(module)
  })
}

const examination = (resolve) => {
  import('@/views/examination/examination').then((module) => {
    resolve(module)
  })
}

const Detail = (resolve) => {
  import('@/views/examination/children/detail').then((module) => {
    resolve(module)
  })
}

const comfirmInfo = (resolve) => {
  import('@/views/examination/children/comfirmInfo').then((module) => {
    resolve(module)
  })
}

const message = (resolve) => {
  import('@/views/message/message').then((module) => {
    resolve(module)
  })
}

const messageDetail = (resolve) => {
  import('@/views/message/messageDetail').then((module) => {
    resolve(module)
  })
}

const messageContent = (resolve) => {
  import('@/views/message/msgContent').then((module) => {
    resolve(module)
  })
}

const OldPeopleHome = (resolve) => {
  import('@/views/oldPeopleHome/oldPeopleHome').then((module) => {
    resolve(module)
  })
}

const OldPeopleHomeDetail = (resolve) => {
  import('@/views/oldPeopleHome/oldPeopleHomeDetial').then((module) => {
    resolve(module)
  })
}

const location = (resolve) => {
  import('@/components/location/location').then((module) => {
    resolve(module)
  })
}

const addNewLocation = (resolve) => {
  import('@/components/location/children/addNewLocation').then((module) => {
    resolve(module)
  })
}

const selectLocation = (resolve) => {
  import('@/components/location/children/selectLocation').then((module) => {
    resolve(module)
  })
}

// const shop = r => require.ensure([], () => r(require('@/views/shop/shop')), 'shop')
// const pay = r => require.ensure([], () => r(require('@/views/pay')), 'pay')
// const payment = r => require.ensure([], () => r(require('@/components/payment/payment')), 'pay')
// const examination = r => require.ensure([], () => r(require('@/views/examination/examination')), 'examination')
// const Detail = r => require.ensure([], () => r(require('@/views/examination/children/detail')), 'examination')
// const comfirmInfo = r => require.ensure([], () => r(require('@/views/examination/children/comfirmInfo')), 'comfirmInfo')
// const message = r => require.ensure([], () => r(require('@/views/message/message')), 'message')

Vue.use(Router)

export default new Router({
  // mode: "history",
  routes: [
    {
      path: '/',
      name: 'main',
      redirect: '/home',
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/search',
      name: 'search',
      component: Search
    },
    {
      path: '/personal',
      name: 'personal',
      component: Personal,
      children: [
        {
          path: 'setting',
          name: 'setting',
          component: Setting
        },
        {
          path: 'familyMembers',
          name: 'familyMembers',
          component: familyMembers,
          children: [
            {
              path: ':id',
              children: [
                {
                  path: 'changeInfo'
                }
              ]
            }
          ]
        },
        {
          path: 'myDoctor',
          component: mydoctor
        }
      ]
    },
    {
      path: '/shop',
      name: 'shop',
      component: shop
    },
    {
      path: '/pay',
      component: pay,
      children: [
        {
          path: '/payment',
          name: 'payment',
          component: payment
        }
      ]
    },
    {
      path: '/examination',
      name: 'examination',
      component: examination,
      children: [
        {
          path: 'detail',
          component: Detail
        }
      ]
    },
    {
      path: '/comfirmInfo',
      component: comfirmInfo,
      children: [
        {
          path: '/comfirmInfoPay',
          component: payment
        }
      ]
    },
    {
      path: '/message',
      component: message,
      children:[
        {
          path: 'messageDetail',
          component: messageDetail,
          children: [
            {
              path: 'messageContent',
              component: messageContent
            }
          ]
        }
      ]
    },
    {
      path: '/oldPeopleHome',
      component: OldPeopleHome,
      children: [
        {
          path: 'OldPeopleHomeDetail',
          component: OldPeopleHomeDetail
        }
      ]
    },
    {
      path: '/location',
      component: location,
      children: [
        {
          path: 'addNewLocation',
          component: addNewLocation,
          children: [
            {
              path: 'selectLocation',
              component: selectLocation
            }
          ]
        }
      ]
    }
  ]
})
